#/*
# -----------------------------------------------------------------------------
# Filename:    CMakeLists.txt
# -----------------------------------------------------------------------------
#
# This source file is part of
#  _____            ___               
# /__   \__      __/___\__ _ _ __ ___ 
#   / /\/\ \ /\ / //  // _` | '__/ _ \
#  / /    \ V  V / \_// (_| | | |  __/
#  \/      \_/\_/\___/ \__, |_|  \___|
#                      |___/          
# 
#	  Ogre wrapper for the AntTweakBar GUI library
# -----------------------------------------------------------------------------
#	  TwOgre Project: http://code.google.com/p/twogregui/
#	  Ogre3D: http://www.ogre3d.org/
#     AntTweakBar: http://www.antisphere.com/Wiki/tools:anttweakbar
# -----------------------------------------------------------------------------
# TwOgre is licensed under the Simplified BSD License:
#
# Copyright (c) 2007-2010, the TwOgre Project
# All rights reserved.
# 
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions
#   and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
#   and the following disclaimer in the documentation and/or other materials provided with the distribution.
# * Neither the name of TwOgre nor the names of its contributors may be used to endorse or promote
#   products derived from this software without specific prior written permission.
# 
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------
#*/

project(TwOgre)

cmake_minimum_required(VERSION 2.6)

# Works around warnings libraries linked against that don't
# have absolute paths (e.g. -lOgreMain)
cmake_policy(SET CMP0003 NEW)

# Works around warnings about escaped quotes in ADD_DEFINITIONS
# statements.
cmake_policy(SET CMP0005 NEW)

cmake_policy(SET CMP0010 OLD)

# include our custom cmake scripts
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)

if (CMAKE_BUILD_TYPE STREQUAL "")
  # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up
  # differentiation between debug and release builds.
  set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None (CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif ()
 
set(CMAKE_DEBUG_POSTFIX "_d")
 
set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/dist")
set(TWOGRE_BIN_DIR "${CMAKE_CURRENT_BINARY_DIR}")
 
option(TWOGRE_BUILD_DEMO "Build Demo Application" TRUE)

find_package(OGRE REQUIRED)
 
if(NOT "${OGRE_VERSION_NAME}" STREQUAL "Cthugha")
  message(SEND_ERROR "You need Ogre 1.7 Cthugha to build this.")
endif()
 
find_package(OIS REQUIRED)
 
if(NOT OIS_FOUND)
    message(SEND_ERROR "Failed to find OIS.")
endif()
 
# Find Boost
if (NOT OGRE_BUILD_PLATFORM_IPHONE)
	if (WIN32 OR APPLE)
		set(Boost_USE_STATIC_LIBS TRUE)
	else ()
		# Statically linking boost to a dynamic Ogre build doesn't work on Linux 64bit
		set(Boost_USE_STATIC_LIBS ${OGRE_STATIC})
	endif ()
	if (MINGW)
		# this is probably a bug in CMake: the boost find module tries to look for
		# boost libraries with name libboost_*, but CMake already prefixes library
		# search names with "lib". This is the workaround.
		set(CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES} "")
	endif ()
	set(Boost_ADDITIONAL_VERSIONS "1.42" "1.42.0" "1.41.0" "1.41" "1.40.0" "1.40" "1.39.0" "1.39" "1.38.0" "1.38" "1.37.0" "1.37" )
	# Components that need linking (NB does not include header-only components like bind)
	set(OGRE_BOOST_COMPONENTS thread date_time)
	find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET)
	if (NOT Boost_FOUND)
		# Try again with the other type of libs
		set(Boost_USE_STATIC_LIBS NOT ${Boost_USE_STATIC_LIBS})
		find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET)
	endif()
	find_package(Boost QUIET)
 
	# Set up referencing of Boost
	include_directories(${Boost_INCLUDE_DIR})
	add_definitions(-DBOOST_ALL_NO_LIB)
	set(OGRE_LIBRARIES ${OGRE_LIBRARIES} ${Boost_LIBRARIES})
endif()

if(UNIX)
	find_package(OpenGL)
	set(OGRE_LIBRARIES ${OGRE_LIBRARIES} ${OPENGL_LIBRARY})

set(TWOGRE_SOURCE
	src/LoadOGL.cpp
	src/TwBar.cpp
	src/TwColors.cpp
	src/TwFonts.cpp
	src/TwMgr.cpp
	src/TwOgreBoolVariable.cpp
	src/TwOgreButtonVariable.cpp
	src/TwOgreColorVariable.cpp
	src/TwOgreDirection3DVariable.cpp
	src/TwOgrePosition3DVariable.cpp
	src/TwOgreQuaternionVariable.cpp
	src/TwOgreEnumVariable.cpp
	src/TwOgreIntegerVariable.cpp
	src/TwOgreRealVariable.cpp
	src/TwOgreSeparatorVariable.cpp
	src/TwOgreStringVariable.cpp
	src/TwOgreVariable.cpp
	src/TwOgreWindow.cpp
	src/TwOgreWindowManager.cpp
	src/TwOpenGL.cpp
	src/TwPrecomp.cpp
)

set(TWOGRE_HEADERS
	include/AntPerfTimer.h
	include/AntTweakBar.h
	include/LoadOGL.h
	include/TwBar.h
	include/TwColors.h
	include/TwFonts.h
	include/TwGraph.h
	include/TwMgr.h
	include/TwOgre.h
	include/TwOgreBoolVariable.h
	include/TwOgreButtonVariable.h
	include/TwOgreColorVariable.h
	include/TwOgreDirection3DVariable.h
	include/TwOgrePosition3DVariable.h
	include/TwOgreQuaternionVariable.h
	include/TwOgreEnumVariable.h
	include/TwOgreIntegerVariable.h
	include/TwOgrePrerequisites.h
	include/TwOgreRealVariable.h
	include/TwOgreSeparatorVariable.h
	include/TwOgreStringVariable.h
	include/TwOgreVariable.h
	include/TwOgreWindow.h
	include/TwOgreWindowManager.h
	include/TwOpenGL.h
	include/TwPrecomp.h
	include/resource.h
)

endif(UNIX)
 


if(WIN32)
set(TWOGRE_SOURCE
	src/LoadOGL.cpp
	src/TwBar.cpp
	src/TwColors.cpp
	src/TwDirect3D10.cpp
	src/TwDirect3D9.cpp
	src/TwFonts.cpp
	src/TwMgr.cpp
	src/TwOgreBoolVariable.cpp
	src/TwOgreButtonVariable.cpp
	src/TwOgreColorVariable.cpp
	src/TwOgreDirection3DVariable.cpp
	src/TwOgrePosition3DVariable.cpp
	src/TwOgreQuaternionVariable.cpp
	src/TwOgreEnumVariable.cpp
	src/TwOgreIntegerVariable.cpp
	src/TwOgreRealVariable.cpp
	src/TwOgreSeparatorVariable.cpp
	src/TwOgreStringVariable.cpp
	src/TwOgreVariable.cpp
	src/TwOgreWindow.cpp
	src/TwOgreWindowManager.cpp
	src/TwOpenGL.cpp
	src/TwPrecomp.cpp
)

set(TWOGRE_HEADERS
	include/AntPerfTimer.h
	include/AntTweakBar.h
	include/LoadOGL.h
	include/TwBar.h
	include/TwColors.h
	include/TwDirect3D10.h
	include/TwDirect3D9.h
	include/TwFonts.h
	include/TwGraph.h
	include/TwMgr.h
	include/TwOgre.h
	include/TwOgreBoolVariable.h
	include/TwOgreButtonVariable.h
	include/TwOgreColorVariable.h
	include/TwOgreDirection3DVariable.h
	include/TwOgrePosition3DVariable.h
	include/TwOgreQuaternionVariable.h
	include/TwOgreEnumVariable.h
	include/TwOgreIntegerVariable.h
	include/TwOgrePrerequisites.h
	include/TwOgreRealVariable.h
	include/TwOgreSeparatorVariable.h
	include/TwOgreStringVariable.h
	include/TwOgreVariable.h
	include/TwOgreWindow.h
	include/TwOgreWindowManager.h
	include/TwOpenGL.h
	include/TwPrecomp.h
	include/d3d10vs2003.h
	include/resource.h
)

SOURCE_GROUP("AntTweakBar Header Files"
	FILES
	include/AntPerfTimer.h
	include/AntTweakBar.h
	include/LoadOGL.h
	include/TwBar.h
	include/TwColors.h
	include/TwDirect3D10.h
	include/TwDirect3D9.h
	include/TwFonts.h
	include/TwGraph.h
	include/TwMgr.h
	include/TwOpenGL.h
	include/TwPrecomp.h
	include/d3d10vs2003.h
	include/resource.h
)

SOURCE_GROUP("AntTweakBar Source Files"
	FILES
	src/LoadOGL.cpp
	src/TwBar.cpp
	src/TwColors.cpp
	src/TwDirect3D10.cpp
	src/TwDirect3D9.cpp
	src/TwFonts.cpp
	src/TwMgr.cpp
	src/TwOpenGL.cpp
	src/TwPrecomp.cpp
)
endif(WIN32)

include_directories( "include"
	${OIS_INCLUDE_DIRS}
	${OGRE_INCLUDE_DIRS}
	${OGRE_SAMPLES_INCLUDEPATH}
)

if(UNIX)
	include_directories(include/GL ${X11_INCLUDE_DIR})
endif(UNIX)

add_library(twogre STATIC ${TWOGRE_SOURCE} ${TWOGRE_HEADERS})
set_target_properties(twogre PROPERTIES DEBUG_POSTFIX _d)

if(UNIX)
	set_target_properties(twogre PROPERTIES
	    COMPILE_DEFINITIONS "_UNIX")
endif(UNIX)

set(LIBRARY_OUTPUT_PATH  lib)
target_link_libraries(twogre ${OGRE_LIBRARIES})

if(TWOGRE_BUILD_DEMO)
    add_subdirectory("demo/Example_WorldEditor")
endif(TWOGRE_BUILD_DEMO)

